﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using FarseerPhysics.Collision.Shapes;
using FarseerPhysics.Common;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Joints;
using FarseerPhysics.Factories;

namespace MountainORocks
{
    public class dropStuff
    {
        int dropCount = 0;
        double timeBeforeDrop;
        double timeBeforeDropConst;
        bool randomPlace;
        Vector2 locationToDrop;
        Game1 myGame;
        ShapeType myType;
        ShapeM myM;
        Vector2 mySize;
        bool isStatic;
        public static System.Random generator = new System.Random();
        bool randomShape, rand=false;
        bool followPlayer = false;


        public dropStuff(Vector2 tmpSize, bool tmpStatic, double tmpTime, int tmpCoun, Game1 tmpGame, int x, int y,bool rand)
        {
            if (tmpTime < 0)
            {
                timeBeforeDrop = generator.Next((int)Math.Abs(tmpTime));
                timeBeforeDropConst = tmpTime;

            }
            else
            {
                timeBeforeDrop = tmpTime;
                timeBeforeDropConst = tmpTime;
            }
            dropCount = tmpCoun;
            randomPlace = true;
            if (x <= 0 & y <= 0)
                locationToDrop = Vector2.Zero;
            else
            {
                randomPlace = false;
                locationToDrop = new Vector2(x, y);
            }
            myGame = tmpGame;
            mySize = tmpSize;
            isStatic = tmpStatic;
            randomShape = true;
            this.rand = rand;

        }


        public dropStuff(Vector2 tmpSize, bool tmpStatic, double tmpTime, int tmpCoun, Game1 tmpGame, Vector2 tmpPlace)
        {
            if (tmpTime < 0)
            {
                timeBeforeDrop = generator.Next((int)Math.Abs(tmpTime));
                timeBeforeDropConst = tmpTime;

            }
            else
            {
                timeBeforeDrop = tmpTime;
                timeBeforeDropConst = tmpTime;
            }
            
            dropCount = tmpCoun;
            randomPlace = false;
            locationToDrop = tmpPlace;
            myGame = tmpGame;
            mySize = tmpSize;
            isStatic = tmpStatic;
            randomShape = true;

        }

        public dropStuff(ShapeType tmpType, ShapeM tmpM, Vector2 tmpSize, bool tmpStatic, double tmpTime, int tmpCoun, Game1 tmpGame)
        {
            myM = tmpM;
            myType = tmpType;
            if (tmpTime < 0)
            {
                timeBeforeDrop = generator.Next((int)Math.Abs(tmpTime));
                timeBeforeDropConst = tmpTime;

            }
            else
            {
                timeBeforeDrop = tmpTime;
                timeBeforeDropConst = tmpTime;
            }
            dropCount = tmpCoun;
            randomPlace = true;
            locationToDrop = Vector2.Zero;
            myGame = tmpGame;
            mySize = tmpSize;
            isStatic = tmpStatic;
            randomShape = false;

        }

        public dropStuff(ShapeType tmpType, ShapeM tmpM, Vector2 tmpSize, bool tmpStatic, double tmpTime, int tmpCoun, Game1 tmpGame, Vector2 tmpPlace)
        {
            myM = tmpM;
            myType = tmpType;
            if (tmpTime < 0)
            {
                timeBeforeDrop = generator.Next((int)Math.Abs(tmpTime));
                timeBeforeDropConst = tmpTime;

            }
            else
            {
                timeBeforeDrop = tmpTime;
                timeBeforeDropConst = tmpTime;
            }
            dropCount = tmpCoun;
            randomPlace = false;
            if (tmpPlace.X < 0)
            {
                followPlayer = true;

            }
            
            locationToDrop = tmpPlace;
            myGame = tmpGame;
            mySize = tmpSize;
            isStatic = tmpStatic;
            randomShape = false;

        }

        public float getSizeX()
        {
            return mySize.X;
        }

        public float getSizeY()
        {
            return mySize.Y;
        }

        public int getXplace()
        {
            return (int)locationToDrop.X;
        }

        public int getYplace()
        {
            return (int)locationToDrop.Y;
        }

        public bool getStatic()
        {
            return isStatic;
        }

        public double getTmpTime()
        {
            return timeBeforeDropConst;
        }

        public int getCount()
        {
            return dropCount;
        }

        public bool getrand()
        {
            return rand;
        }

        public void update(GameTime gameTime)
        {
            timeBeforeDrop -= gameTime.ElapsedGameTime.TotalSeconds;
            if (((dropCount > 0) || (dropCount<0)) && (timeBeforeDrop<0))
            {
                if (timeBeforeDropConst<0)
                    timeBeforeDrop = generator.Next((int)Math.Abs(timeBeforeDropConst)) + 1;
                else
                    timeBeforeDrop = timeBeforeDropConst;
                dropCount--;
                if (randomPlace)
                {
                    locationToDrop.X = generator.Next(0 + 5, myGame.WIDTH - 5);
                    locationToDrop.Y = 0;

                }
                if(rand)
                {
                    locationToDrop.X = generator.Next((int)locationToDrop.X - 25, (int)locationToDrop.X + 25);

                }

                if (followPlayer)
                {
                    locationToDrop = myGame.charBody.Position;
                }

                if (randomShape)
                {
                    myType = ShapeType.Circle;
                    int randM = generator.Next(3);
                    if (randM == 0)
                        myM = ShapeM.Wood;
                    if (randM == 1)
                        myM = ShapeM.Stone;
                    if (randM == 2)
                        myM = ShapeM.Glass;



                }

                myGame.rocks.Add(new GameShape(myGame.world, myType, myM, new Rectangle((int)locationToDrop.X, (int)locationToDrop.Y, (int)mySize.X, (int)mySize.Y),isStatic));

            }


        }


    }
}
